import Vue from 'vue'
import Router from 'vue-router'
import NProgress from 'nprogress'
import home from '@/components/home'
import managePage from '@/components/manage'
import displayPage from '@/components/display'
import notFond from '@/components/not-fond'

Vue.use(Router)
const router = new Router({
    routes: [{
            path: '/',
            name: "home",
            component: home,
            redirect:'/home-manage',
            children: [{
                    path: 'home-manage',
                    name: "manage-page",
                    component: managePage,
                },
                {
                    path: 'home-display',
                    name: "display-page",
                    component: displayPage,
                }
            ]
        },
        {
            path: '/manage',
            name: "manage-page",
            component: managePage,
        },
        {
            path: '/display',
            name: "display-page",
            component: displayPage,
        },
        {
            path: '*',
            name: "not-fond",
            component: notFond,
        }
    ]
})

//路由跳转前做点什么
router.beforeEach((to, from, next) => {
    // console.log(to)
    //开始进度条
    NProgress.start();
    next()
});

//路由跳转后做点什么
router.afterEach(to => {
    // window.scrollTo(0, 0)
    //结束进度条
  NProgress.done();
});
export default router;